package com.qf.fc.controller;


import com.qf.fc.Param.UserDto;
import com.qf.fc.Param.UserPass;
import com.qf.fc.entity.User;
import com.qf.fc.service.UserService;
import com.qf.fc.vo.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import java.util.List;
import java.util.Map;


/**
 * 用户表(User)表控制层
 *
 * @author makejava
 * @since 2024-09-16 22:55:52
 */
@RestController  //标记是控制器，内部有映射方法
@RequestMapping("/api/user/") //设置接口前缀
@Tag(name="用户接口")  //knife4j 接口文档
public class UserController{
    /**
     * 服务对象
     */
    @Resource
    private UserService service;


    /**
     * 发送手机验证码
     */
    @GetMapping("code")
    public R<String> sendCode(String phone, HttpSession session) {
        // TODO 发送短信验证码并保存验证码
        return service.sentCode(phone,session);
    }

    @GetMapping("checkphone")
    public R<String> checkPhone(String phone){
        return service.checkPhone(phone);
    }
    @PostMapping("register")
    public R<String> register(@RequestBody UserDto userDto){
        return service.register(userDto);
    }
    @PostMapping("login")
    public R<Map> login(@RequestBody UserDto dto, HttpSession session){
        return service.login(dto,session);
    }
    @GetMapping("logout")
    public R<String> logout(String token){
        return service.logout(token);
    }
    @PostMapping("findpass")
    public R<String> findPass(@RequestBody UserDto dto){
        return service.findPass(dto);
    }
    @PostMapping("updatepass")
    public R<String> updatePass(@RequestBody UserPass pass){
        return service.updatePass(pass);
    }

    @GetMapping("all")
    public R<List<User>> all(String phone){
        return service.queryByPhone(phone);
    }
}

